package com.darrenchan.leetcode;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-04-19 17:34
 */
public class QLint891 {
    public boolean validPalindrome(String s) {
        if(s == null || s.length() == 0) {
            return true;
        }
        int i = 0, j = s.length() - 1;
        while(i < j) {
            if(s.charAt(i) != s.charAt(j)) {
                break;
            }
            i++;
            j--;
        }
        if(i >= j) {
            return true;
        }

        return isPali(s, i + 1, j) || isPali(s, i, j - 1);
    }

    public boolean isPali(String s, int i, int j) {
        while(i < j) {
            if(s.charAt(i) != s.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
}
